package com.siyu.model.dispatch.model;

import com.siyu.model.dispatch.dto.DispatchDto;
import com.siyu.model.dispatch.io.FloodDispatchInput;
import com.siyu.model.dispatch.io.FloodDispatchOutput;
import com.siyu.model.dispatch.io.SingleDamOutput;
import com.siyu.model.dispatch.model.interfaces.Model;

import java.lang.reflect.Constructor;
import java.util.List;

/**
 * 模型测试类：按照提示的编号规则输入对应的模型类型编号和流域编号，即可测试模型效果
 *
 * @author xinchan
 * @version 1.0.1 2022-05-01
 */
public class DispatchModel {
    /**
     *
     * @param dispatchDto
     * @throws Exception
     */
    public static FloodDispatchOutput dispatch(DispatchDto dispatchDto) throws Exception {
        String path = "siyu-model/src/main/resources/cache/Singlersvr";
        String classPath = "com.siyu.model.dispatch.model."+dispatchDto.getDispatchType()+".singlersvr.SingleRsvr";
        // 创建模型
        Class<?> clazz = Class.forName(classPath);
        Constructor<?> constructor = clazz.getConstructor(String.class);
        Model model = (Model) constructor.newInstance(path);
        //  参数初始化
        FloodDispatchInput input = model.initModel(dispatchDto);
     /*   if (input == null) {
            return null;
        }*/
        // 模型计算
        FloodDispatchOutput output = model.calculate(input);
        return output;
    }

    public static void main(String[] args) throws Exception {
        DispatchDto dispatchDto = new DispatchDto();
        FloodDispatchOutput dispatch = dispatch(dispatchDto);
        for (SingleDamOutput singleDamOutput : dispatch.getDamList()) {
            // 获取时初水位
            List<Double> optimalLineLevel = singleDamOutput.getOptimalLine_Level();
            // 获取泄流能力
            List<Double> maxQreleaseFromLQ = singleDamOutput.getMaxQreleaseFromLQ();
            // 获取下泄流量
            List<Double> optimalLineQrelease = singleDamOutput.getOptimalLine_Qrelease();
            // 入库洪峰
            double floodPeak = singleDamOutput.getFloodPeak();
            // 入库洪量
            double floodVolume = singleDamOutput.getFloodVolume();
            // 最大泄洪
            double floodDischarge = singleDamOutput.getFloodDischarge();
            // 拦蓄水量
            double floodRetention = singleDamOutput.getFloodRetention();
            // 削峰率
            double peakClippingRate = singleDamOutput.getPeakClippingRate();
            // 调度建议
            String suggestion = singleDamOutput.getSuggestion();
            System.out.println("计算完成");
        }
    }
}
